//
//  UIButton+Extension.swift
//  globalcarbusiness
//
//  Created by dongzhenyu on 2017/8/12.
//  Copyright © 2017年 dongzhenyu. All rights reserved.
//

import UIKit

extension UIButton {
    
    // 定义便利构造器
    convenience init(imageName: String, backgroundImage: String) {
        
        self.init()
        
        setImage(UIImage(named: imageName), for: .normal)
        setImage(UIImage(named:imageName + "_highlighted"), for: .highlighted)
        
        setBackgroundImage(UIImage(named: backgroundImage), for: .normal)
        setBackgroundImage(UIImage(named: backgroundImage + "_highlighted"), for: .highlighted)
        
    }
    
    
    convenience init(title: String, textColor: UIColor, backgroundImage: String) {
        
        self.init()
        
        setTitle(title, for: .normal)
        setTitleColor(textColor, for: .normal)
        setBackgroundImage(UIImage(named: backgroundImage), for: .normal)
    }
    
    convenience init(title: String, imageName: String) {
        self.init()
        
        setImage(UIImage(named:imageName), for: .normal)
        setTitle(title, for: .normal)
        setTitleColor(UIColor.lightGray, for: .normal)
        adjustsImageWhenHighlighted = false
        titleLabel?.font = UIFont.systemFont(ofSize: 15)
//        titleEdgeInsets = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 0)

    }

}
